package com.foreknow.demo14;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Scanner;

/**
 * @author shkstart
 * @create 2021-08-03 14:20
 */
public class guestBookTest {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
       DBUtil dbUtil=new DBUtil();
        try {
            dbUtil.connect();

            System.out.println("请输入查询id");
            String id = sc.next();
            ResultSet rs = dbUtil.search("select * from guestbook where id=?", id);

            while (rs.next()) {
                int id1 = rs.getInt("id");
                String name = rs.getString("name");
                String phone = rs.getString("phone");
                String email = rs.getString("email");
                String title = rs.getString("title");
                String content = rs.getString("content");

                System.out.println(id1+","+name+","+phone+","+email+","+title+","+content);
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        System.out.println("请输入要的修改的id");
        String upid = sc.next();

        try {
            dbUtil.connect();
            ResultSet  search = dbUtil.search("select * from guestbook where id=?", upid);
            System.out.println(search.getInt("id"));
            System.out.println("请修改");
////            System.out.println("(" + search.getInt("id") + "):");
////            int upid1 = sc.nextInt();
//            System.out.println("(" + search.getString("name") + "):");
//            String upname = sc.next();
//            System.out.println("(" + search.getString("phone") + "):");
//            String upphone = sc.next();
//            System.out.println("(" + search.getString("email") + "):");
//            String upemail = sc.next();
//            System.out.println("(" + search.getString("title")+ "):");
//            String uptitle = sc.next();
//            System.out.println("(" + search.getString("content") + "):");
//            String upcon = sc.next();
//            dbUtil.update("update set name=?,phone=?,email=?,title=?,content=?where id ="+upid,upname,upphone,upemail,uptitle,upcon );

        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }


    }



}
